
const UserServer = require('../service/users')
const path = require('path')

class UserController {

  async index(ctx, next) {
    let { data } = await UserServer.index(ctx, next)
    ctx.body = {
      data
    }
  }

  async page(ctx, next) {
    let { data, total } = await UserServer.page(ctx, next)
    ctx.body = {
      code: 0,
      msg: 'success',
      total: total[0].num,
      data
    }
  }
  async upload(ctx) {
    console.log(ctx.request, 'ctx.request')
    console.log(ctx.request.files, 'ctx.request.files')
    const file = ctx.request.files.file;
    const basename = path.basename(file.path);
    ctx.body = { url: `${ctx.origin}/uploads/${basename}` };
  }

  async login(ctx) {
    console.log('ddd')
    const data = await UserServer.login(ctx);
    ctx.body = {
      data
    }
  }
}

module.exports = new UserController